package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.Makesheet;
import com.ruoyi.huanghefd.service.MakesheetService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author gnplum
 * @Date 2023/11/11 15:44
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: MakesheetController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class MakesheetController {
    private static final Logger log = LoggerFactory.getLogger(MakesheetController.class);

    @Resource
    private MakesheetService makesheetService;

    /**
     * @Author gnplum
     * @Description //新增操作票
     * @Date 9:48 2023/11/11
     * @param makesheets
     * @return com.ruoyi.huanghefd.domain.ResultWS
     * http://localhost:8080/huanghefd/addMakesheet
     **/
    @PostMapping("/addMakesheet")
    public AjaxResult addMakesheet(@RequestBody Makesheet makesheets){
        String in = JSON.toJSONString(makesheets);
        log.info(">> 新增操作票-入参==" + in);
        AjaxResult ajax = makesheetService.addMakesheet(makesheets);
        log.info("<< 新增操作票-返回==" + ajax.toString());
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //删除操作票
     * @Date 15:22 2023/11/11
     * @param msCode
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/delMakesheet?msId=4e60df22773811eeb08e00e04c738ae4
     **/
    @PostMapping(value = "/delMakesheet")
    public AjaxResult delMakesheet(@RequestParam(required = false,value = "msCode") String msCode){
        log.info(">> 删除操作票-入参 msCode==" + msCode);
        if(msCode.isEmpty()){
            return AjaxResult.success("请点选要删除的工作票");
        }
        AjaxResult ajax = makesheetService.delMakesheet(msCode);
        log.info(">> 删除操作票-返回==" + ajax);
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //修改操作票
     * @Date 15:47 2023/11/11
     * @param makesheets
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/uptMakesheet
     **/
    @PostMapping(value = "/uptMakesheet")
    public AjaxResult uptMakesheet(@RequestBody Makesheet makesheets){
        log.info(">> 修改操作票-入参 ==" + makesheets);
        AjaxResult ajax = makesheetService.uptMakesheet(makesheets);
        log.info(">> 修改操作票-返回 ==" + ajax);
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //查询操作票
     * @Date 9:48 2023/11/11
     * @param msCode,msDept,msState
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:18080/huanghefd/queryMakesheet?msCode=20231102000001&msDept=100
     **/
    @PostMapping(value = "/queryMakesheet")
    public AjaxResult queryMakesheetList(@RequestParam(required = false,value = "msCode") String msCode,@RequestParam(required = false,value = "msDept") String msDept,@RequestParam(required = false,value = "msState") String msState,@RequestParam(required = false,value = "userId") String userId,@RequestParam(required = false,value = "mailType") String mailType){
        log.info(">> 查询操作票-入参==" + msCode + "," + msDept + "," + msState + "," + userId + "," + mailType);
        AjaxResult ajax = makesheetService.queryMakesheets(msCode, msDept, msState, userId, mailType);//mailType 1-收件箱 2-发件箱
        log.info(">> 查询操作票-返回==" + ajax);
        return ajax;
    }
    /**
     * @Author gnplum
     * @Description //查询操作票 分页
     * @Date 11:42 2024/1/3
     * @param msCode
     * @param msDept
     * @param msState
     * @param userId
     * @param mailType
     * @param pageNum
     * @param pageSize
    * @return com.ruoyi.huanghefd.utils.PageBean
    **/
    @PostMapping(value = "/queryMakesheet1")
    public PageBean queryMakesheetList(@RequestParam(required = false,value = "msCode") String msCode, @RequestParam(required = false,value = "msDept") String msDept, @RequestParam(required = false,value = "msState") String msState, @RequestParam(required = false,value = "userId") String userId, @RequestParam(required = false,value = "mailType") String mailType, @RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize){
        log.info(">> 查询操作票-入参==" + msCode + "," + msDept + "," + msState + "," + userId + "," + mailType);
        PageBean ajax = makesheetService.queryMakesheetsByPage(msCode, msDept, msState, userId, mailType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询操作票-返回==" + ajax);
        return ajax;
    }

}
